package com.zyh.blogs.controller;

import com.zyh.blogs.entity.Article;
import com.zyh.blogs.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/article")
public class ArticleController {


    @Autowired
    ArticleService articleService;

    @RequestMapping("/getList")
    public String getList(Model model, Integer page, Integer size) {
        page = page == null ? 0 : page - 1;
        size = size == null ? 3 : size;
        Page<Article> articles = articleService.queryList(page, size);
        int totalPages = articles.getTotalPages();
        Pageable pageable = articles.getPageable();
        int pageSize = pageable.getPageSize();
        int pageNumber = pageable.getPageNumber();
        long offset = pageable.getOffset();
        model.addAttribute("list", articles);
        return "index";
    }



}
